Skip to content

Method: create(String, List)

1: package de.fhdw.wtf.generator.java.generatorModel;
2:
3: import java.util.Iterator;
4: import java.util.List;
5:
6: import de.fhdw.wtf.generator.transformer.clipper.ClipToFileTask;
7:
8: /**
9: * Represents the signature of a GenJavaOperation to make operations comparable.
10: */
11: public final class GenOperationSignature {
12:         
13:         /**
14:          * Name of the Operation.
15:          */
16:         private final String name;
17:         
18:         /**
19:          * Parameters of the operation.
20:          */
21:         private final List<GenParameter> parameters;
22:         
23:         /**
24:          * Private Constructor.
25:          *
26:          * @param name
27:          * - name of the operation
28:          * @param parameters
29:          * - parameters of the operation
30:          */
31:         private GenOperationSignature(final String name, final List<GenParameter> parameters) {
32:                 this.name = name;
33:                 this.parameters = parameters;
34:         }
35:         
36:         /**
37:          * Factory Method for {@link GenOperationSignature}.
38:          *
39:          * @param name
40:          * - name of the operation.
41:          * @param parameters
42:          * - parameters of the operation.
43:          * @return - new Signature-Object.
44:          */
45:         public static GenOperationSignature create(final String name, final List<GenParameter> parameters) {
46:                 return new GenOperationSignature(name, parameters);
47:         }
48:         
49:         /**
50:          * Returns the parameters of the operation.
51:          *
52:          * @return - parameters
53:          */
54:         public List<GenParameter> getParameters() {
55:                 return this.parameters;
56:         }
57:         
58:         /**
59:          * Returns the name of the operation.
60:          *
61:          * @return - name
62:          */
63:         public String getName() {
64:                 return this.name;
65:         }
66:         
67:         @Override
68:         public boolean equals(final Object obj) {
69:                 if (obj instanceof GenOperationSignature) {
70:                         final GenOperationSignature other = (GenOperationSignature) obj;
71:                         if (this.getName().equals(other.getName())) {
72:                                 return GenOperationSignature.equalsParamTypes(this.getParameters(), other.getParameters());
73:                         }
74:                 }
75:                 return false;
76:         }
77:         
78:         @Override
79:         public int hashCode() {
80:                 return this.getName().hashCode() ^ this.getParameters().hashCode();
81:         }
82:         
83:         @Override
84:         public String toString() {
85:                 final StringBuffer result = new StringBuffer(this.name);
86:                 result.append('(');
87:                 if (!this.parameters.isEmpty()) {
88:                         for (final GenParameter param : this.parameters) {
89:                                 result.append(param);
90:                                 result.append(',');
91:                         }
92:                         result.deleteCharAt(result.length() - 1);
93:                 }
94:                 result.append(')');
95:                 return result.toString();
96:         }
97:         
98:         /**
99:          * Returns true, if and only if the param types equal in name.
100:          *
101:          * @param a
102:          * first operation
103:          * @param b
104:          * second operation
105:          * @return see above
106:          */
107:         public static boolean equalsParamTypes(final List<GenParameter> a, final List<GenParameter> b) {
108:                 if (a.size() == b.size()) {
109:                         final Iterator<GenParameter> i = a.iterator();
110:                         final Iterator<GenParameter> j = b.iterator();
111:                         while (i.hasNext()) {
112:                                 final GenParameter currentI = i.next();
113:                                 if (j.hasNext()) {
114:                                         final GenParameter currentJ = j.next();
115:                                         if (!ClipToFileTask.replaceIllegalChars(
116:                                                         currentI.getTyp().getFullyQualifiedNameWithGenericArguments()).equals(
117:                                                         ClipToFileTask.replaceIllegalChars(currentJ.getTyp()
118:                                                                         .getFullyQualifiedNameWithGenericArguments()))) {
119:                                                 return false;
120:                                         }
121:                                 }
122:                         }
123:                 }
124:                 return true;
125:         }
126:         
127: }